package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {
  public static final String SHOP_STATUS = "shop:status";
  
  @Autowired
  private RedisTemplate redisTemplate;
  
  /**
   * 设置营业状态
   * @param statusCode 1 营业 0 打烊
   * @return
   */
  @PutMapping("/{status}")
  public Result setStatus(@PathVariable("status") Integer statusCode) {
    log.info("设置营业状态为：{}", statusCode);
    redisTemplate.opsForValue().set(SHOP_STATUS, statusCode);
    return Result.success();
  }
  
  /**
   * h获取店铺营业状态
   * @return
   */
  @GetMapping("/status")
  public Result<Integer> getStatus() {
    Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
    return Result.success(status);
  }
}
